﻿using Apps.Common;
using Apps.Models;
using System.Linq;
using System.Collections.Generic;
using Apps.Models.PL;

namespace Apps.BLL.PL
{
    public partial class PL_RL_DETAILSBLL
    {

        public override List<PL_RL_DETAILSModel> GetListByParentId(ref GridPager pager, string queryStr, object parentId)
        {
            IQueryable<PL_RL_DETAILS> queryData = null;
            string pid = parentId.ToString();
            if (pid != "0")
            {
                queryData = m_Rep.GetList(a => a.PUB_CREW.CREW_ID == pid);
            }
            else
            {
                queryData = m_Rep.GetList();
            }
            if (!string.IsNullOrWhiteSpace(queryStr))
            {
                queryData = m_Rep.GetList(
                            a => (
                                    a.TEAM_ID.Contains(queryStr)
                                   || a.DETAIL_ID.Contains(queryStr)
                                   || a.CREW_ID.Contains(queryStr)
                                   || a.CREATE_USER_ID.Contains(queryStr)
                                   || a.BATCH_CODE.Contains(queryStr)
                                 )
                            );
            }
            pager.totalRows = queryData.Count();
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return CreateModelList(ref queryData);
        }
        public override List<PL_RL_DETAILSModel> CreateModelList(ref IQueryable<PL_RL_DETAILS> queryData)
        {

            List<PL_RL_DETAILSModel> modelList = (from r in queryData
                                                  select new PL_RL_DETAILSModel
                                                  {
                                                      DETAIL_ID = r.DETAIL_ID,
                                                      CREW_ID = r.CREW_ID,
                                                      TEAM_ID = r.TEAM_ID,
                                                      BATCH_CODE = r.BATCH_CODE,
                                                      STATUS = r.STATUS,
                                                      CREATE_USER_ID = r.CREATE_USER_ID,
                                                      CREATE_TIME = r.CREATE_TIME,
                                                      PLAN_DATE = r.PLAN_DATE,
                                                      TEAMName = r.PUB_TEAM.TEAM_NAME,
                                                      CREWName = r.PUB_CREW.CREW_NAME,
                                                  }).ToList();
            return modelList;
        }
        public override PL_RL_DETAILSModel GetById(object id)
        {
            if (IsExists(id))
            {

                PL_RL_DETAILS entity = m_Rep.GetById(id);
                PL_RL_DETAILSModel model = new PL_RL_DETAILSModel();
                model.DETAIL_ID = entity.DETAIL_ID;
                model.CREW_ID = entity.CREW_ID;
                model.TEAM_ID = entity.TEAM_ID;
                model.BATCH_CODE = entity.BATCH_CODE;
                model.STATUS = entity.STATUS;
                model.CREATE_USER_ID = entity.CREATE_USER_ID;
                model.CREATE_TIME = entity.CREATE_TIME;
                model.PLAN_DATE = entity.PLAN_DATE;
                model.TEAMName = entity.PUB_TEAM.TEAM_NAME;
                model.CREWName = entity.PUB_CREW.CREW_NAME;
                return model;
            }
            else
            {
                return null;
            }
        }
    }
 }

